// state state对象
// payload 传入的参数对象
// mutiations不处理数据类型，默认数据都在action做过处理

import {cutPoints} from 'utils/map';
import {setPageData} from 'utils/page';

const SET_ZOOM_DATA = 'SET_ZOOM_DATA';
const SET_LOCAL_OVERLAYS = 'SET_LOCAL_OVERLAYS';
const SET_LOCAL_REFERENCE = 'SET_LOCAL_REFERENCE';
const SET_OVERLAYS_DATA = 'SET_OVERLAYS_DATA';
const SET_REFERENCE_DATA = 'SET_REFERENCE_DATA';
const REMOVE_OVERLAYS_DATA = 'REMOVE_OVERLAYS_DATA';
const REMOVE_REFERENCE_DATA = 'REMOVE_REFERENCE_DATA';
const INIT_MAP_OBJ = 'INIT_MAP_OBJ';

export default {
    //设置地图聚焦参数
    [SET_ZOOM_DATA](state, obj){
        state.zoom = Object.assign(state.zoom, obj);
        setPageData('zoom', state.zoom);
    },
    //设置本地存储的形状数据
    [SET_LOCAL_OVERLAYS](state, obj){
        state.overlaysPoints = Object.assign(state.overlaysPoints, obj);
    },
    //设置本地存储的参照物数据
    [SET_LOCAL_REFERENCE](state, obj){
        state.referencePoints = Object.assign(state.referencePoints, obj);
    },
    //设置标记形状数据
    [SET_OVERLAYS_DATA](state, obj){
        state.overlays = Object.assign(state.overlays, obj);
        let points = cutPoints(state.overlays);
        setPageData('overlaysPoints', points);
    },
    //设置参照物形状数据
    [SET_REFERENCE_DATA](state, obj){
        state.reference = Object.assign(state.reference, obj);
        let points = cutPoints(state.reference);
        setPageData('referencePoints', points);
    },
    //移除已标记的形状
    [REMOVE_OVERLAYS_DATA](state, obj){
        state.overlays = obj;
        let points = cutPoints(state.overlays);
        setPageData('overlaysPoints', points);
    },
    //移除参照物形状
    [REMOVE_REFERENCE_DATA](state, obj){
        state.reference = obj;
        let points = cutPoints(state.reference);
        setPageData('referencePoints', points);
    },
    //初始化地图
    [INIT_MAP_OBJ](state, obj){
        state.mapObj = obj;
    }
}